<template>
	<view>
		<mine-head title="系统设置"></mine-head>
		<view class="list">
			<view class="item _df _ac _jb" @click="clickFn(item,index)" v-for="(item,index) in list" :key="index">
				<view class="title">
					{{item.title}}
				</view>
				<view class="info">
					{{item.value}}<u-icon class="ml20" name="arrow-right" color="#888" size="26"></u-icon>
				</view>
			</view>
			<view class="h40">
				
			</view>
			<view class="btn-box">
				<u-button class="btn" @click="goExit" size="default" shape="circle" type="primary">退出登录</u-button>
				<!-- <u-button class="btn" :plain="true" @click="exit" size="default" shape="circle" type="primary">注销账号</u-button> -->
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:[
					{
						title:'账号绑定',
						value:'未绑定',
						path:'/pages/setup/account/account',
					},
					{
						title:'消息通知',
						value:'',
						path:'/pages/setup/news',
					},
					{
						title:'意见反馈',
						value:'',
						path:'/pages/setup/message',
					},
					{
						title:'检查更新',
						value:'',
						path:'',
					},
					{
						title:'清理缓存',
						value:'',
						path:'',
					},
					
				],
				user:{},
				cache_size:''
			};
		},
		onLoad() {
			
		},
		onShow() {
			this.getHeartSet()
			this.getUser()
			this.getCacheSize()
		},
		methods:{
			getCacheSize() {
				plus.cache.calculate((size) => {
					let new_size = size / (1024 * 1024)
					if (new_size < 1024) {
						this.list[4].value = (new_size).toFixed(2) + 'MB'
					} else {
						this.list[4].value = (new_size / 1024).toFixed(2) + 'GB'
					}
				})
			},
			clearCache() { 
				plus.cache.clear(() => {
					uni.showToast({
						title: '清除成功!',
						icon: 'none',
						success: () => {
							this.list[4].value = '0.00MB'
						}
					})
				})
			},
			goSeting(){
				uni.openAppAuthorizeSetting({
					success: function () {
						console.log('打开系统设置页面成功');
					},
					fail: function () {
						console.log('打开系统设置页面失败');
					}
				});
			},
			getUser() {
				let that = this;
				uni.$_get({
					url: "get-user",
					that: that,
					success(res) {
						let _data = res.data;
						if (res.code == 0) {
							that.user = _data
							that.list[0].value = _data.phone
						}
			
					},
					fail(err) {
			
					},
				});
			},
			getHeartSet(){
				let that = this
				uni.$_get({
					url: "getHeartSet",
					that: that,
					success(res) {
						console.log(res)
						let _data = res.data;
						if(res.code == 0){
							
						}else{
							uni.showToast({
								title: res.msg,
								duration: 2000,
								icon:'error'
							});
						}
					},
					fail(err) {
						uni.showToast({
							title: err.msg,
							duration: 1000,
							icon:'error'
						});	
					},
				});
			},
			clickFn(e,index){
				let that = this
				if(index == 1){
					this.goSeting()
				}else if(index == 4){
					uni.$_publicModal(
					  "清理缓存可能导致数据异常，确定清理？",
					  function () {
					    that.clearCache()
					  }
					);
					
				}
				else if(index == 3){
					uni.showToast({
						title:'应用上架后可使用',
						icon:'none'
					})
				}
				else{
					uni.navigateTo({
						url:e.path
					})
				}
			},
			goExit() {
				uni.$_publicModal('确定退出当前账号？', function() {
			// 		uni.removeStorage({
			// 			key: 'user',
			// 			success: function(res) {
			
			// 			}
			// 		});
					uni.removeStorage({
						key: 'token',
						success: function(res) {
			
						}
					});
					uni.$_navFn("too", "/pages/login/login");
				})
			},
			exit(){
				
			},
		},
	}
</script>

<style lang="scss" scoped>
.list{
	padding: 30rpx 50rpx;
	.item{
		height: 106rpx;
		border-bottom: 1rpx solid #e5e5e5;
		.info{
			font-size: 24rpx;
			color: #aaa;
		}
		.title{
			font-size: 30rpx;
			color: #111;
			font-family: $uni-font-family-Bold;
		}
	}
}
.btn{
	margin: 30rpx 0;
}
/deep/.u-btn--primary{
		background-color: #6387FF;
		border-color: #6387FF;
	}
.btn-box{
	position: fixed;
	bottom: 40rpx;
	left: 0;
	width: 100%;
	padding: 0 50rpx;
	box-sizing: border-box;
}
</style>
